package com.foreveross.fetl.core.domain.task;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Query;

import org.springframework.transaction.annotation.Transactional;

import com.dayatang.domain.InstanceFactory;
import com.foreveross.fetl.common.domain.BaseEntity;
import com.foreveross.fetl.core.domain.task.repository.ITaskTemplateAssignDayRepository;

/**
 * 指定抓取间隔时间的任务模版
 */
@javax.persistence.Entity
@javax.persistence.Table(name = "CRAWL_TASK_TEMPLATE_ASSIGNDAY")
public class TaskTemplateAssignDayEntity extends BaseEntity {
	private static final long serialVersionUID = -8919716605426792555L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private Long id;
	/**
	 * 对应的模版
	 */
	@Column(name = "TEMPLATE_ID")
	private Long templateId;
	/**
	 * 起飞的时间类型，1指定日期区间，2未来固定日期天数，3 未来每周周几，4每月第几天，5每季第几天
	 */
	@Column(name = "DAY_TYPE")
	private Integer dayType = 2;
	/**
	 * 指定的距离当天的起飞时间间隔,根据上面的类型不同含义也不同，为１指定日期区间时，该值没有作用，为２未来天数，该值表示未来第几天
	 * 为３周几，则表示周几.....
	 */
	@Column(name = "ASSIGN_FLIGHT_DAY")
	private Integer assignFlightDay;
	/**
	 * 指定的距离起飞时间的回程时间间隔
	 */
	@Column(name = "ASSIGN_ROUND_DAY")
	private Integer assignRoundDay;
	/**
	 * 固定日期开始
	 */
	@Column(name = "START_DATE")
	private Date startDate;
	/**
	 * 固定日期结束
	 */
	@Column(name = "END_DATE")
	private Date endDate;
	/**
	 * 未来周期，对应于上面的dayType，如果是周几，代表未来连续的多少周周几，如果是月，代表未来连续多少个月的月第几天
	 */
	@Column(name = "FUTURE_CYCLE")
	private Integer futureCycle = 0;

	public Long getTemplateId() {
		return templateId;
	}

	public void setTemplateId(Long templateId) {
		this.templateId = templateId;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getAssignFlightDay() {
		return assignFlightDay;
	}

	public void setAssignFlightDay(Integer assignFlightDay) {
		this.assignFlightDay = assignFlightDay;
	}

	public Integer getAssignRoundDay() {
		return assignRoundDay;
	}

	public void setAssignRoundDay(Integer assignRoundDay) {
		this.assignRoundDay = assignRoundDay;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Integer getDayType() {
		return dayType;
	}

	public void setDayType(Integer dayType) {
		this.dayType = dayType;
	}

	public Integer getFutureCycle() {
		return futureCycle;
	}

	public void setFutureCycle(Integer futureCycle) {
		this.futureCycle = futureCycle;
	}

	public List<TaskTemplateAssignDayEntity> findByCondition(Long templateId) {
		getTaskTemplateAssignDayRepository().findByCondition(templateId);
		return null;
	}

	public ITaskTemplateAssignDayRepository getTaskTemplateAssignDayRepository() {
		return InstanceFactory
				.getInstance(ITaskTemplateAssignDayRepository.class);
	}

	@Transactional
	public void saveOrUpdate(TaskTemplateAssignDayEntity entity) {
		if (null != entity.getId()) {
			getTaskTemplateAssignDayRepository().update(entity);
			return;
		}
		getTaskTemplateAssignDayRepository().save(entity);
	}

	@Transactional
	public void delete(TaskTemplateAssignDayEntity entity) {
		getTaskTemplateAssignDayRepository().delete(entity);
	}

	public Query createQuery(String hql, Object[] params) {
		return getTaskTemplateAssignDayRepository().createQuery(hql, params);
	}

	public TaskTemplateAssignDayEntity get(Long id) {
		return getTaskTemplateAssignDayRepository().find(
				TaskTemplateAssignDayEntity.class, id);
	}
}
